import 'package:get/get.dart';
import 'package:kkhousekeep/config/constant.dart';
import 'package:kkhousekeep/net/home_bill_connect.dart';

import '../../../../models/home_bill_details_entity.dart';

class BillDetailsController extends GetxController {
  int year = -1;
  int month = -1;

  late BillConnect _connect;

  var address = ''.obs;

  var totalMoney = (0.0).obs;

  var items = <HomeBillDetailsObjItems>[].obs;

  @override
  void onInit() {
    year = Get.arguments[ArgumentKey.year] ?? year;
    month = Get.arguments[ArgumentKey.month] ?? month;
    _connect = Get.find<BillConnect>();
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
    _connect.getBillDetails(year: year, month: month).then((value) {
      address.value = value.address;
      totalMoney.value = value.totalMoney;
      items.value = value.items;
    });
  }
}

enum BillState {
  unknown(id: -1, color: 0XFF7C7E80, name: '未知'),
  paid(id: 2, color: 0XFF55D4A5, name: '已缴费'),
  noPaid(id: 3, color: 0XFFDD5045, name: '待缴费'),
  suspended(id: 4, color: 0XFF1774E0, name: '已挂起'),
  refund(id: 5, color: 0XFF7C7E80, name: '已退费'),
  obsolete(id: 6, color: 0XFF7C7E80, name: '已作废');

  final int id;
  final int color;
  final String name;

  const BillState({
    required this.id,
    required this.color,
    required this.name,
  });

  static BillState getBillStateById(int id) {
    return BillState.values.firstWhereOrNull((element) => element.id == id) ??
        BillState.unknown;
  }
}

enum FeeType {
  unknown(id: -1, name: '未知'),
  repeatFee(id: 1, name: '周期性收费'),
  onceFee(id: 2, name: '一次性收费'),
  meterFee(id: 3, name: '仪表类收费项目');

  final int id;
  final String name;

  const FeeType({
    required this.id,
    required this.name,
  });

  static FeeType getFeeTypeById(int id) {
    return FeeType.values.firstWhereOrNull((element) => element.id == id) ??
        FeeType.unknown;
  }
}
